package cn.qyd.kaoshi;

import java.util.*;

/**
 * @author 邱运铎
 * @date 2024-03-20 19:25
 */
public class Demo02 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            int n = Integer.parseInt(in.nextLine());
            String[] strArray = new String[2];
            TreeMap<Integer,Integer> map = new TreeMap<>();
            for (int i = 0; i < n; i++) {
                strArray = in.nextLine().split(" ");
                map.put(Integer.parseInt(strArray[0]),map.getOrDefault(Integer.parseInt(strArray[0]),0) + Integer.parseInt(strArray[1]));
            }

            for (Map.Entry entry : map.entrySet()) {
                System.out.println(entry.getKey() + " " + entry.getValue());
            }
        }
    }
}
